package com.xzz.trieTree;

import java.util.List;

/**
 * @author: hhz
 * @create: 2022-01-20 11:29
 * 677. 键值映射
 **/
public class MapSum {
    TrieMap<Integer> trieMap;
    public MapSum() {
        trieMap = new TrieMap<>();
    }

    public void insert(String key, int val) {
        trieMap.put(key,val);
    }

    public int sum(String prefix) {
        int res = 0;
        List<String> stringList = trieMap.keysWithPrefix(prefix);
        for (String s : stringList) {
            res+= trieMap.get(s);
        }
        return res;
    }
}
